<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <!-- <li>
                             父节点：<input type="text" name="parentId"/>
                         </li>

                         <li>
                             祖节点：<input type="text" name="ancestors"/>
                         </li>

                         <li>
                             城市编码：<input type="text" name="citycode"/>
                         </li>

                         <li>
                             区域编码：<input type="text" name="adcode"/>
                         </li>
 -->
                        <li>
                            行政区名称：<input type="text" name="name"/>
                        </li>

                        <li>
                            行政区划级别：<input type="text" name="level"/>
                        </li>
                        <!--

                                                <li>
                                                    创建者：<input type="text" name="createBy"/>
                                                </li>

                                                <li>
                                                    创建时间：<input type="text" name="createTime"/>
                                                </li>

                                                <li>
                                                    更新者：<input type="text" name="updateBy"/>
                                                </li>

                                                <li>
                                                    更新时间：<input type="text" name="updateTime"/>
                                                </li>
                        -->

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add('1')" shiro:hasPermission="sys:area:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editTree()"
               shiro:hasPermission="sys:area:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
            <!--
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="sys:area:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="sys:area:export">
						<i class="fa fa-download"></i> 导出
				 </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "sys/area";

    $(function () {
        var options = {
            code: "id",
            parentCode: "parentId",
            uniqueId: "id",
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "区域",
            expandAll: false,
            expandFirst: true,
            columns: [
                {
                    field: 'selectItem',
                    radio: true
                },
                // {
                //     field: 'parentId',
                //     title: '父节点',
                //     align: "left"
                // },
                // {
                //     field: 'ancestors',
                //     title: '祖节点',
                //     align: "left"
                // },
                {
                    field: 'citycode',
                    title: '城市编码',
                    align: "left"
                },
                {
                    field: 'adcode',
                    title: '区域编码',
                    align: "left"
                },

                {
                    field: 'name',
                    title: '行政区名称',
                    align: "left"
                },
                {
                    field: 'level',
                    title: '行政区划级别',
                    align: "left",
                    formatter: function (value, item, index) {
                        if (value == 'country') {
                            return '国家';
                        } else if (value == 'province') {
                            return '省';
                        } else if (value == 'city') {
                            return '市';
                        } else {
                            return '区';
                        }
                    }
                },
                // {
                //     field: 'createBy',
                //     title: '创建者',
                //     align: "left"
                // },
                // {
                //     field: 'createTime',
                //     title: '创建时间',
                //     align: "left"
                // },
                // {
                //     field: 'updateBy',
                //     title: '更新者',
                //     align: "left"
                // },
                // {
                //     field: 'updateTime',
                //     title: '更新时间',
                //     align: "left"
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info  btn-xs" href="#" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus">新增</i></a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="#" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.treeTable.init(options);

        function remove(id) {
            $.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗？", function () {
                $.ajax({
                    type: 'post',
                    url: prefix + "/remove/" + id,
                    success: function (result) {
                        if (result.code == web_status.SUCCESS) {
                            $.modal.msgSuccess(result.msg);
                            $.treeTable.refresh();
                        } else {
                            $.modal.msgError(result.msg);
                        }
                    }
                });
            });
        }
    });
</script>
</body>
</html>